package com.ruoyi.crm.service.impl;
import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.crm.mapper.CrmCustomersMapper;
import com.ruoyi.crm.domain.CrmCustomers;
import com.ruoyi.crm.service.ICrmCustomersService;

import javax.annotation.Resource;

/**
 * 客户Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-09-23
 */
@Service
public class CrmCustomersServiceImpl implements ICrmCustomersService
{
    @Resource
    private CrmCustomersMapper crmCustomersMapper;

    /**
     * 查询客户
     * 
     * @param custUuid 客户主键
     * @return 客户
     */
    @Override
    public CrmCustomers selectCrmCustomersByCustUuid(String custUuid)
    {
        return crmCustomersMapper.selectCrmCustomersByCustUuid(custUuid);
    }

    /**
     * 查询客户列表
     * 
     * @param crmCustomers 客户
     * @return 客户
     */
    @Override
    public List<CrmCustomers> selectCrmCustomersList(CrmCustomers crmCustomers)
    {
        return crmCustomersMapper.selectCrmCustomersList(crmCustomers);
    }
  /**
     * 查询客户表中的序号
     *
     * @param crmCustomers 客户
     * @return 用于新增时序号自增长
     */
    @Override
    public List<CrmCustomers> findOrderNum(CrmCustomers crmCustomers)
    {
        return crmCustomersMapper.findOrderNum(crmCustomers);
    }
    /**
     * 查询客户列表
     *
     * @param crmCustomers 客户
     * @return 客户
     */
    @Override
    public List<CrmCustomers> selectCrmCustomersFindGroupName(CrmCustomers crmCustomers)
    {
        return crmCustomersMapper.selectCrmCustomersFindGroupName(crmCustomers);
    }

    /**
     * 新增客户
     * 
     * @param crmCustomers 客户
     * @return 结果
     */
    @Override
    public int insertCrmCustomers(CrmCustomers crmCustomers)
    {
        crmCustomers.setCreateBy( SecurityUtils.getUsername() );
        return crmCustomersMapper.insertCrmCustomers(crmCustomers);
    }

    /**
     * 修改客户
     * 
     * @param crmCustomers 客户
     * @return 结果
     */
    @Override
    public int updateCrmCustomers(CrmCustomers crmCustomers)
    {
        crmCustomers.setUpdateBy( SecurityUtils.getUsername() );
        crmCustomers.setUpdateTime(DateUtils.getNowDate());
        return crmCustomersMapper.updateCrmCustomers(crmCustomers);
    }

    /**
     * 校验用户名称是否唯一
     *
     * @param custName 用户名称
     * @return 结果
     */
    @Override
    public String checkCustNameUnique(String custName)
    {
        int count = crmCustomersMapper.checkCustNameUnique(custName);
        if (count > 0)
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 校验用户名称是否唯一
     *
     * @param docNum 用户名称
     * @return 结果
     */
    @Override
    public String checkDocNumUnique(String docNum)
    {
        int count = crmCustomersMapper.checkDocNumUnique(docNum);
        if (count > 0)
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 批量删除客户
     * 
     * @param custUuids 需要删除的客户主键
     * @return 结果
     */
    @Override
    public int deleteCrmCustomersByCustUuids(String[] custUuids)
    {
        return crmCustomersMapper.deleteCrmCustomersByCustUuids(custUuids);
    }

    /**
     * 删除客户信息
     * 
     * @param custUuid 客户主键
     * @return 结果
     */
    @Override
    public int deleteCrmCustomersByCustUuid(String custUuid)
    {
        return crmCustomersMapper.deleteCrmCustomersByCustUuid(custUuid);
    }
}
